package com.itzg.vboxfarm.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.ImportResource;
import org.springframework.context.annotation.Profile;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.annotation.ScopedProxyMode;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;

import com.itzg.vboxfarm.service.Services;

@Configuration
@ComponentScan(basePackageClasses=Services.class, scopedProxy=ScopedProxyMode.TARGET_CLASS)
@EnableAsync
@Import({JpaConfig.class})
@ImportResource({"/WEB-INF/spring/bits.xml"})
@PropertySource("classpath:com/itzg/vboxfarm/config/defaults.properties")
public class AppConfig {
	
	@Bean
	public ThreadPoolTaskScheduler taskScheduler() {
		return new ThreadPoolTaskScheduler();
	}
	
	@Bean
	public PropertySourcesPlaceholderConfigurer propertyPlaceholder() {
		return new PropertySourcesPlaceholderConfigurer();
	}
	
	/**
	 * Properties to support the 'embedded' mode of operation.
	 */
	@Configuration
	@Profile("embedded")
	@PropertySource("classpath:" + "com/itzg/vboxfarm/config/"
			+ "embedded.properties")
	static class Embedded {
	}

	/**
	 * Properties to support the 'standard' mode of operation.
	 */
	@Configuration
	@Profile("standard")
	@PropertySource("classpath:application.properties")
	static class Standard {
	}
}
